const axios = require('axios');
axios.defaults.withCredentials = true;

module.exports = function(url,args) {

    if(!url) {
        throw new Error("client need a url");
    }

    if(typeof args != "object") {
        throw new Error("args must be Object");
    }

    const config = {
        "method" : args.method ? args.method : "POST",
        "url": url,
        "headers": args.headers ? args.headers : {} ,
        "responseType": args.dataType || "json",
        "data": args.data ? args.data : ''
    }

    return axios(config).then(response=> {
        const data = {
            status: response.status,
            data: response.data
        };
        return data;
    });

}
